package com.itheima.exception;

import com.itheima.result.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
public class UserAddGoblException {
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R<String> exception(SQLIntegrityConstraintViolationException e) {
        String[] s = e.getMessage().split(" ");
        return R.error("您输入的用户名" + s[2] + "已被占用");
    }

    @ExceptionHandler(CustExcepiton.class)
    public R<String> exceptions(CustExcepiton e) {
        return R.error(e.getMessage());
    }

}
